import requests

from contant.gaode import *


class GaodeServiceService:
    @classmethod
    def add_service(cls, name: str, desc: str):
        """
        创建服务
        :param name: 服务名称
        :param desc: 服务描述
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'name': name,
            'desc': desc
        }
        # 发送HTTP请求
        response = requests.post(GAODE_SERVICE_ADD, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def update_service(cls, sid: str, name: str, desc: str):
        """
        修改服务
        :param sid: 服务编号
        :param name: 服务名称
        :param desc: 服务描述
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'name': name,
            'desc': desc
        }
        # 发送HTTP请求
        response = requests.post(GAODE_SERVICE_UPDATE, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def delete_service(cls, sid: str):
        """
        删除服务
        :param sid: 服务编号
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid
        }
        # 发送HTTP请求
        response = requests.post(GAODE_SERVICE_DELETE, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def query_service(cls):
        """
        查询服务列表
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY
        }
        # 发送HTTP请求
        response = requests.get(GAODE_SERVICE_LIST, params=post_data)
        # 解析JSON响应
        data = response.json()
        return data
